import {Component} from '@angular/core';
import {NavController, NavParams, Config} from 'ionic-angular';
import {UserProvider} from "../../providers/user/user";

@Component({
  selector: 'page-investment-record',
  templateUrl: 'investment-record.html',
})
export class InvestmentRecordPage{

  type: number = 0
  investList: object[] = []
  nowPage: number = -1
  last: boolean = false

  investFinishList: object[] = []
  nowPageFinish: number = -1
  lastFinish: boolean = false

  constructor(public navCtrl: NavController,
              public config: Config,
              private user: UserProvider,
              public navParams: NavParams) {
    // super(config)
  }

  ionViewDidEnter() {
    this.getInvest()
    this.getInvestFinish()
  }

  getInvest(page = 0, success = () => {
  }) {
    this.user.getInvest({
      data:{
        page: page
      },
      success: (data) => {
        this.investList = this.investList.concat(data.content)
        this.nowPage += 1
        this.last = data.lastPage
        success()
      }
    })
  }

  getInvestFinish(page = 0, success = () => {
  }) {
    this.user.getInvestFinish({
      data:{
        page: page
      },
      success: (data) => {
        this.investFinishList = this.investFinishList.concat(data.content)
        this.nowPageFinish += 1
        this.lastFinish = data.lastPage
        success()
      }
    })
  }

  getMore(infiniteScroll) {
    setTimeout(() => {
      this.getInvest(this.nowPage + 1, () => {
        infiniteScroll.complete()
      })
    }, 500);
  }

  getMoreFinish(infiniteScroll) {
    setTimeout(() => {
      this.getInvestFinish(this.nowPageFinish + 1, () => {
        infiniteScroll.complete()
      })
    }, 500);
  }

}
